﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NexTrackDesktop.Media;
using System.Windows;

namespace NexTrackDesktop.NexTrack
{
    /// <summary>
    /// This class contains nextrack instance and communicates with web service
    /// </summary>
    public class Client
    {
        #region Singleton Instance
        private static Client _instance = new Client();
        public static Client Instance
        {
            get
            {
                return _instance;
            }
        }
        #endregion
        
        private Client()
        {
            ThumbnailCache = new ThumbnailCache();

            if (MessageBox.Show("ITERATION 1 TESTING ONLY:\n\nWould you like to connect to the actual NexTrack server?", "Testing", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                WebService = new NexTrackServiceAdapter();
            else
                WebService = new MainServiceMock();

            Player = new NexTrackPlayer();
        }

        public ThumbnailCache ThumbnailCache { get; set; }
        public MainServiceAdapter WebService { get; set; }
        public Party Party { get; private set; }
        public Library MediaLibrary { get; private set; }
        public NexTrackPlayer Player { get; private set; }

        public event Action PartyLoaded;
        public event Action MusicStarting;

        /// <summary>
        /// This method loads the specified party.
        /// </summary>
        /// <param name="party">Party to load</param>
        public void LoadParty(Party party)
        {
            Party = party;
            if (PartyLoaded != null)
                PartyLoaded();
        }

        /// <summary>
        /// This method starts the music for the party.
        /// </summary>
        public void StartMusic()
        {
            if (MusicStarting != null)
                MusicStarting();

            Party.NextSong();
        }
    }
}
